package com.health.system.common.utils;


import com.health.system.security.auth.entity.HealthSecurityAuthDetails;
import org.springframework.security.core.context.SecurityContextHolder;

/**
 * Security用户信息获取工具类
 *
 */
public class UserAuthUtil {
    private UserAuthUtil() {

    }

    public static HealthSecurityAuthDetails currentUser() {
//        HealthSecurityAuthDetails defaultAuth = HealthSecurityAuthDetails.builder()
//                .id(1L)
//                .nickName("test")
//                .build();

        HealthSecurityAuthDetails currentAuth =  (HealthSecurityAuthDetails)SecurityContextHolder.getContext().getAuthentication().getPrincipal();
//        return currentAuth != null && currentAuth != "anonymousUser"? (BlogSecurityAuthDetails) currentAuth : defaultAuth;
        return currentAuth;
    }

    public static Long authId() {
        return currentUser().getId();
    }

    public static String nickName() {
        return currentUser().getNickName();
    }

}
